

//

const arrayProto=Array.prototype

export const arrayMethods=Object.create(arrayProto)

const methodsToPatch=[
  'push',
  'pop',
  'shift',
  'unshift',
  'reserve',
  'sort',
  'splice',
]

methodsToPatch.forEach(method=>{
  arrayMethods[key]=function(...args){
    const result = arrayProto[method].apply(this,args)

    this.__ob__=this

    let inserter;
    switch(method){
      case 'push':
      case 'unshift':
        inserter=args
        break;
      case 'splice':
        inserter=args.slice(2)
      default:
        break;
    }

    if(inserter) ob.observer(inserter)
    
    return result
  }
})